import {MovieModel} from "../../../models/movie";
const movies=new MovieModel;
import {list} from "../../../utils/util";
// const app=getApp();
Page({
  data: {
   start:0
  },

  onLoad: function (options) {
    // console.log(options)
    var id=options.id;
    if(id==0){
      movies.getIntheaters(res=>{
        this.handleData(res)
      })
    }else if(id==1){
      movies.getComingsoon(res=>{
        this.handleData(res)
      })
    }else if(id==2){
      movies.getTop250(res=>{
        this.handleData(res)
      })
    }else if(id==3){
      movies.getUsbox(res=>{
        var title=res.title;
        // wx.setNavigationBarTitle({
        //   title
        // })
        var movies=[];
        res.subjects.forEach(ele=>{
          // console.log(ele)
          var ele=ele.subject;
          var title=ele.title;
          var average=ele.rating.average;
          var year=ele.title+'('+ele.year+')';
          var directors=ele.directors[0].name;
          var imgUrl=ele.images.small;
          var id=ele.id;
          var temp={
            title,
            average,
            year,
            directors,
            imgUrl,
            id,
          }
          movies.push(temp)
        })
        var readyData={
          movies,
          title,
        };
        this.setData(readyData)
      })
    }
   wx.hideLoading()
  },
  handleData(res){
    // console.log(res)
    var title=res.title;
    wx.setNavigationBarTitle({
      title,
    })
    var movies=list(res.subjects)
    var readyData={
      movies,
      title,
    };
    this.setData(readyData)
  },
})